package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zzw.domain.DepartmentManage;
import com.ruoyi.zzw.service.TDepartmentManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 部门Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/department")
public class BackDepartmentManageController extends BaseController
{
    @Autowired
    private TDepartmentManageService tDepartmentManageService;

    /**
     * 查询部门列表
     */
    @PreAuthorize("@ss.hasPermi('system:department:list')")
    @GetMapping("/list")
    public AjaxResult list(DepartmentManage departmentManage)
    {

        List<DepartmentManage> list = tDepartmentManageService.selectTDepartmentManageList(departmentManage);
        return success(list);
    }

    /**
     * 导出部门列表
     */
    @PreAuthorize("@ss.hasPermi('system:department:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DepartmentManage departmentManage)
    {
        List<DepartmentManage> list = tDepartmentManageService.selectTDepartmentManageList(departmentManage);
        ExcelUtil<DepartmentManage> util = new ExcelUtil<DepartmentManage>(DepartmentManage.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:department:query')")
    @GetMapping(value = "/{cDepartmentId}")
    public AjaxResult getInfo(@PathVariable("cDepartmentId") Long cDepartmentId)
    {
        return success(tDepartmentManageService.selectTDepartmentManageByCDepartmentId(cDepartmentId));
    }

    /**
     * 新增部门
     */
    @PreAuthorize("@ss.hasPermi('system:department:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DepartmentManage departmentManage)
    {
        return toAjax(tDepartmentManageService.insertTDepartmentManage(departmentManage));
    }

    /**
     * 修改部门
     */
    @PreAuthorize("@ss.hasPermi('system:department:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DepartmentManage departmentManage)
    {
        return toAjax(tDepartmentManageService.updateTDepartmentManage(departmentManage));
    }

    /**
     * 删除部门
     */
    @PreAuthorize("@ss.hasPermi('system:department:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cDepartmentIds}")
    public AjaxResult remove(@PathVariable Long[] cDepartmentIds)
    {
        return toAjax(tDepartmentManageService.deleteTDepartmentManageByCDepartmentIds(cDepartmentIds));
    }
}
